import { stringify } from 'qs';
import fetch from 'dva/fetch';
import { getActivities, getNotice, getFakeList } from '../../mock/api';
import { getRule, postRule } from '../../mock/rule';
import request from '../utils/request';
import jsonrequest from '../utils/jsonrequest';
import { SIMAPI_HOST } from '../utils/host';
import { getFakeChartData } from '../../mock/chart';
import { getProfileAdvancedData, getProfileBasicData } from '../../mock/profile';
import { platform } from 'os';
import { getCity, getToken } from '../utils/authority';

export async function queryText(url) {
  return jsonrequest(url);
}
export async function queryProjectNotice() {
  return getNotice;
}
export async function queryProgramDet(params) {
  return request('/vehad/v1/programDet', {
    method: 'GET',
    body: params,
  });
}

export async function getCompany(params) {
  return request('/vehad/v1/companyIdCodes', {
    method: 'GET',
    body: params,
  });
}

export async function getCityCodes(params) {
  return request('/vehad/v1/cityCodes', {
    method: 'GET',
    body: params,
  });
}

export async function fetchUserCodes(params) {
  return request(
    '/vehUser/v1/authUserCodes',
    {
      method: 'GET',
      body: params,
    },
    'vehUser',
    { 'Content-Type': 'application/json' }
  );
}

export async function queryAreaInfo(params) {
  return request(
    '/vehad/v1/adThrowInAreas',
    {
      method: 'GET',
      body: params,
    },
    'ad',
    { 'Content-Type': 'application/json' }
  );
}
export async function getAreaShape(params) {
  return request(
    '/vehad/v1/adTiAreaShapeCodes',
    {
      method: 'GET',
      body: params,
    },
    'ad',
    { 'Content-Type': 'application/json' }
  );
}
export async function getAreaType(params) {
  return request(
    '/vehad/v1/adTiAreaTypeCodes',
    {
      method: 'GET',
      body: params,
    },
    'ad',
    { 'Content-Type': 'application/json' }
  );
}
export async function addArea(params) {
  const token = getToken();
  return request(
    `/vehad/v1/addAdTiArea?token=${token}`,
    {
      method: 'POST',
      body: params,
    },
    'ad',
    { 'Content-Type': 'application/json' }
  );
}
export async function editArea(params) {
  const token = getToken();
  return request(
    `/vehad/v1/editAdTiArea?token=${token}`,
    {
      method: 'POST',
      body: params,
    },
    'ad',
    { 'Content-Type': 'application/json' }
  );
}
export async function removeArea(params) {
  const token = getToken();
  return request(
    `/vehad/v1/delAdTiArea?token=${token}`,
    {
      method: 'POST',
      body: params,
    },
    'ad',
    { 'Content-Type': 'application/json' }
  );
}
export async function getOtaFile(params) {
  return request('/vehad/v1/devUpdateFileCodes', {
    method: 'GET',
    body: params,
  });
}
export async function getOtaMode(params) {
  return request('/vehad/v1/otaFuncModCodes', {
    method: 'GET',
    body: params,
  });
}

export async function queryDevTest(params) {
  return request('/vehad/v1/devTestReps', {
    method: 'GET',
    body: params,
  });
}

export async function queryDevRepairs(params) {
  return request(
    '/vehad/v1/devRepairs',
    {
      method: 'GET',
      body: params,
    },
    'maintain',
    { 'Content-Type': 'application/json' }
  );
}

export async function queryDevAlarm(params) {
  return request(
    '/vehad/v1/devAlarmInfos',
    {
      method: 'GET',
      body: params,
    },
    'maintain',
    { 'Content-Type': 'application/json' }
  );
}

export async function queryDevAlarmDet(params) {
  return request(
    '/vehad/v1/devAlarmDet',
    {
      method: 'GET',
      body: params,
    },
    'maintain',
    { 'Content-Type': 'application/json' }
  );
}

export async function devQueryInfos(params) {
  return request(
    '/vehad/v1/devQueryInfos',
    {
      method: 'GET',
      body: params,
    },
    'maintain'
  );
}
export async function devReSubmit(params) {
  return request(
    '/vehad/v1/subDevRepairForm',
    {
      method: 'POST',
      body: params,
    },
    'maintain',
    { 'Content-Type': 'application/json' }
  );
}

export async function queryDevRepairDet(params) {
  return request(
    '/vehad/v1/devRepairDet',
    {
      method: 'GET',
      body: params,
    },
    'maintain'
  );
}
export async function queryOtaFiles(params) {
  return request('/vehad/v1/devOtaFiles', {
    method: 'GET',
    body: params,
  });
}

export async function uploadOtaFile(params) {
  return request('/vehad/v1/uploadOtaFile', {
    method: 'POST',
    body: params,
  });
}

export async function devUnbind(params) {
  return request(
    '/vehad/v1/devUnbind',
    {
      method: 'POST',
      body: params,
    },
    'maintain'
  );
}

export async function expDevRepairs(params) {
  return request(
    '/vehad/v1/expDevRepairs',
    {
      method: 'GET',
      body: params,
    },
    'maintain'
  );
}

export async function DevTest(params) {
  return request('/vehad/v1/devTestReps', {
    method: 'GET',
    body: params,
  });
}
export async function resetpwd(params) {
  return request(
    '/vehUser/v1/amResetPw',
    {
      method: 'POST',
      body: params,
    },
    'vehUser',
    { 'Content-Type': 'application/json' }
  );
}
export async function addAccount(params) {
  return request(
    '/vehUser/v1/amAddAccount',
    {
      method: 'POST',
      body: params,
    },
    'vehUser',
    { 'Content-Type': 'application/json' }
  );
}

export async function querySmsFlow(params) {
  // return request(
  //   '/devsim/v1/simUsageTrend',
  //   {
  //     method: 'GET',
  //     body: params,
  //   },
  //   'sim',
  //   { 'Content-Type': 'application/json' }
  // );
  return {
    time: '2016-07-14 09:51:35',
    totalUsage: 137.86,
    simUsageTrend: [
      {
        timeCoord: '10/24',
        usage: 23.86,
      },
      {
        timeCoord: '10/25',
        usage: 14,
      },
      {
        timeCoord: '10/26',
        usage: 15,
      },
      {
        timeCoord: '10/27',
        usage: 25,
      },
      {
        timeCoord: '10/28',
        usage: 30,
      },
      {
        timeCoord: '10/29',
        usage: 10,
      },
      {
        timeCoord: '10/30',
        usage: 20,
      },
    ],
    msgId: 1,
  };
}
export async function getUserDet(params) {
  return request(
    '/vehUser/v1/amAccountDet',
    {
      method: 'GET',
      body: params,
    },
    'vehUser',
    { 'Content-Type': 'application/json' }
  );
}

export async function getAppSysPerm() {
  return request(
    '/vehUser/v1/appSysPerm',
    {
      method: 'GET',
    },
    'vehUser',
    { 'Content-Type': 'application/json' }
  );
}
export async function getMenuAuth(params) {
  return request(
    '/vehUser/v1/amMenuPerm',
    {
      method: 'GET',
      body: params,
    },
    'vehUser',
    { 'Content-Type': 'application/json' }
  );
}
export async function getDataAuth() {
  return request(
    '/vehUser/v1/amDataPerm',
    {
      method: 'GET',
    },
    'vehUser',
    { 'Content-Type': 'application/json' }
  );
}

export async function fakeGetAuthority() {}
export async function queryCurrent() {
  // return {
  //   name: 'Serati Ma',

  //   userid: '00000001',
  //   notifyCount: 12,
  // };
  return request(
    '/vehUser/v1/amUserInfo',
    {
      method: 'GET',
    },
    'vehUser',
    { 'Content-Type': 'application/json' }
  );
}
export async function roleExport(params) {
  return request(
    '/vehUser/v1/expAmRoleManage',
    {
      method: 'GET',
      body: params,
    },
    'vehUser',
    { 'Content-Type': 'application/json' }
  );
}
export async function accountExport(params) {
  return request(
    '/vehUser/v1/expAmUserManage',
    {
      method: 'GET',
      body: params,
    },
    'vehUser',
    { 'Content-Type': 'application/json' }
  );
}

export async function queryAccount(params) {
  return request(
    '/vehUser/v1/amUserManage',
    {
      method: 'GET',
      body: params,
    },
    'vehUser',
    { 'Content-Type': 'application/json' }
  );
}
export async function queryProfile() {
  return request(
    '/vehUser/v1/amUserInfo',
    {
      method: 'GET',
    },
    'vehUser',
    { 'Content-Type': 'application/json' }
  );
}

export async function addRole(params) {
  return request(
    '/vehUser/v1/amAddRole',
    {
      method: 'POST',
      body: params,
    },
    'vehUser',
    { 'Content-Type': 'application/json' }
  );
}
export async function saveAccount(params) {
  return request(
    '/vehUser/v1/amEditAccount',
    {
      method: 'POST',
      body: params,
    },
    'vehUser',
    { 'Content-Type': 'application/json' }
  );
}

export async function accountDisable(params) {
  return request(
    '/vehUser/v1/amUserEnable',
    {
      method: 'POST',
      body: params,
    },
    'vehUser',
    { 'Content-Type': 'application/json' }
  );
}

export async function editRole(params) {
  return request(
    '/vehUser/v1/amEditRole',
    {
      method: 'POST',
      body: params,
    },
    'vehUser',
    { 'Content-Type': 'application/json' }
  );
}

export async function saveProfile(params) {
  return request(
    '/vehUser/v1/amSaveUserInfo',
    {
      method: 'POST',
      body: params,
    },
    'vehUser',
    { 'Content-Type': 'application/json' }
  );
}

export async function rmRole(params) {
  return request(
    '/vehUser/v1/amDelRole',
    {
      method: 'POST',
      body: params,
    },
    'vehUser',
    { 'Content-Type': 'application/json' }
  );
}
export async function rmAccount(params) {
  return request(
    '/vehUser/v1/amAccountDel',
    {
      method: 'POST',
      body: params,
    },
    'vehUser',
    { 'Content-Type': 'application/json' }
  );
}

export async function queryRole(params) {
  return request(
    '/vehUser/v1/amRoleManage',
    {
      method: 'GET',
      body: params,
    },
    'vehUser',
    { 'Content-Type': 'application/json' }
  );
}
export async function queryRoleType(params) {
  return request(
    '/vehUser/v1/roleTypeCodes',
    {
      method: 'GET',
      body: params,
    },
    'vehUser',
    { 'Content-Type': 'application/json' }
  );
}
export async function queryUserType(params) {
  return request(
    '/vehUser/v1/userTypeCodes',
    {
      method: 'GET',
      body: params,
    },
    'vehUser',
    { 'Content-Type': 'application/json' }
  );
}
export async function queryUserOrg(params) {
  return request(
    '/vehUser/v1/userOrgNameCodes',
    {
      method: 'GET',
      body: params,
    },
    'vehUser',
    { 'Content-Type': 'application/json' }
  );
}
export async function queryRoleName(params) {
  return request(
    '/vehUser/v1/roleNameCodes',
    {
      method: 'GET',
      body: params,
    },
    'vehUser',
    { 'Content-Type': 'application/json' }
  );
}

export async function getValid() {
  return request('/vehUser/v1/verifyCode', {
    method: 'GET',
  });
}
export async function queryMatList(params) {
  return request('/vehad/v1/programMats', {
    method: 'GET',
    body: params,
  });
}
export async function queryActivities() {
  return getActivities;
}

export async function queryRule(params) {
  return request('/vehad/v1/adMats', {
    method: 'GET',
    body: params,
  });
}
export async function queryVideoCode(params) {
  return request('/vehad/v1/videoFormatCodes', {
    method: 'GET',
    body: params,
  });
}
export async function queryMatTime(params) {
  return request(
    '/vehad/v1/tiSlotCodes',
    {
      method: 'GET',
      body: params,
    },
    'ad'
  );
}

export async function queryDevTask(params) {
  return request('/vehad/v1/setParamTask', {
    method: 'GET',
    body: params,
  });
}

export async function queryPlayList(params) {
  return request(
    '/vehad/v1/vehDevPlayInfo',
    {
      method: 'GET',
      body: params,
    },
    'ad'
  );
}

export async function queryCutInLib(params) {
  return request(
    '/vehad/v1/icMatExamples',
    {
      method: 'GET',
      body: params,
    },
    'breakpub'
  );
}
export async function queryCutInDetail(params) {
  return request(
    '/vehad/v1/icTaskDet',
    {
      method: 'GET',
      body: params,
    },
    'breakpub'
  );
}

export async function queryMatType(params) {
  return request(
    '/vehad/v1/matTypeCodes',
    {
      method: 'GET',
      body: params,
    },
    'breakpub'
  );
}
export async function queryicMatTime(params) {
  return request(
    '/vehad/v1/icPlayTimeCodes',
    {
      method: 'GET',
      body: params,
    },
    'breakpub'
  );
}

export async function queryTempType(params) {
  return request(
    '/vehad/v1/matTemplateCodes',
    {
      method: 'GET',
      body: params,
    },
    'breakpub'
  );
}
export async function updateMatUrl(params) {
  return request(
    '/vehad/v1/updateMatTemplate',
    {
      method: 'POST',
      body: params,
    },
    'breakpub'
  );
}
export async function addMatExample(params) {
  const token = getToken();
  return request(
    `/vehad/v1/createMatExample?token=${token}`,
    {
      method: 'POST',
      body: params,
    },
    'breakpub',
    { 'Content-Type': 'application/json' }
  );
}
export async function addCutInTask(params) {
  const token = getToken();
  return request(
    `/vehad/v1/createInterCutTask?token=${token}`,
    {
      method: 'POST',
      body: params,
    },
    'breakpub',
    { 'Content-Type': 'application/json' }
  );
}

export async function queryImeDetail(params) {
  return request(
    `/vehad/v1/matExampleDet`,
    {
      method: 'GET',
      body: params,
    },
    'breakpub'
  );
}

export async function queryCutInList(params) {
  return request(
    '/vehad/v1/interCutTasks',
    {
      method: 'GET',
      body: params,
    },
    'breakpub'
  );
}
export async function queryCutInLog(params) {
  return request(
    '/vehad/v1/interCutLogs',
    {
      method: 'GET',
      body: params,
    },
    'breakpub'
  );
}

export async function queryTiMatCodes(params) {
  return request(
    '/vehad/v1/tiMatCodes',
    {
      method: 'GET',
      body: params,
    },
    'ad'
  );
}
export async function queryExpVehDevPlayInfo(params) {
  return request(
    '/vehad/v1/expVehDevPlayInfo',
    {
      method: 'GET',
      body: params,
    },
    'ad'
  );
}
export async function queryExpCutInList(params) {
  return request(
    '/vehad/v1/expInterCutTasks',
    {
      method: 'GET',
      body: params,
    },
    'breakpub'
  );
}

export async function setCutInStart(params) {
  return request(
    '/vehad/v1/exeIcTask',
    {
      method: 'POST',
      body: params,
    },
    'breakpub'
  );
}

export async function SetOneKeyOpenScr(params) {
  return request('/vehad/v1/oneKeyOpenScr', {
    method: 'POST',
    body: params,
  });
}

export async function SetOneKeyCloseScr(params) {
  return request('/vehad/v1/oneKeyCloseScr', {
    method: 'POST',
    body: params,
  });
}
export async function SetOneKeyPubLish(params) {
  return request('/vehad/v1/oneKeyPubProgram', {
    method: 'POST',
    body: params,
  });
}
export async function SetOneKeyPubLishApply(params) {
  return request('/vehad/v1/oneKeyPubApply', {
    method: 'POST',
    body: params,
  });
}

export async function removeRule(params) {
  return request('/vehad/v1/delAdMats', {
    method: 'POST',
    body: params,
  });
}
export async function copyRule(params) {
  return request('/vehad/v1/copyProgram', {
    method: 'POST',
    body: params,
  });
}

export async function removeProgram(params) {
  return request('/vehad/v1/delPrograms', {
    method: 'POST',
    body: params,
  });
}
export async function addProgramMat(params) {
  return request('/vehad/v1/addProgMat', {
    method: 'POST',
    body: params,
  });
}
export async function editProgramMat(params) {
  return request('/vehad/v1/editProgMat', {
    method: 'POST',
    body: params,
  });
}

export async function auditProgramMat(params) {
  return request('/vehad/v1/auditProgramMat', {
    method: 'POST',
    body: params,
  });
}

export async function auditProgram(params) {
  return request('/vehad/v1/auditProgram', {
    method: 'POST',
    body: params,
  });
}

export async function auditMat(params) {
  return request('/vehad/v1/auditAdMat', {
    method: 'POST',
    body: params,
  });
}

export async function addRule(params) {
  return request('/api/rule', {
    method: 'POST',
    body: params,
  });
}

// export async function uploadRule(params) {
//   return request('/vehad/v1/uploadAdMat', {
//     method: 'POST',
//     body: params,
//   });
// }
export async function uploadRule(params) {
  return request(
    '/vehad/v1/uploadMatProgAutoEditPub',
    {
      method: 'POST',
      body: params,
    },
    'ad'
  );
}

export async function uploadEditRule(params) {
  return request('/vehad/v1/editAdMat', {
    method: 'POST',
    body: params,
  });
}

export async function queryProgram(params) {
  return request('/vehad/v1/programs', {
    method: 'GET',
    body: params,
  });
}
export async function queryProMatDet(params) {
  return request('/vehad/v1/progMatDet', {
    method: 'GET',
    body: params,
  });
}

export async function queryProgType(params) {
  return request('/vehad/v1/progTypeCodes', {
    method: 'GET',
    body: params,
  });
}

export async function addProgram(params) {
  return request('/vehad/v1/createProgram', {
    method: 'POST',
    body: params,
  });
}

export async function editProgram(params) {
  return request('/vehad/v1/editProgram', {
    method: 'POST',
    body: params,
  });
}

export async function fakeSubmitForm(params) {
  return request('/api/forms', {
    method: 'POST',
    body: params,
  });
}
export async function updateRule(params) {
  return jsonrequest('http://47.106.151.60:10000/vehad/v1/playnew', {
    method: 'POST',
    body: params,
  });
}
export async function publishRule(params) {
  return request('/vehad/v1/pubProgram', {
    method: 'POST',
    body: params,
  });
}
export async function delProgramMat(params) {
  return request('/vehad/v1/delProgramMat', {
    method: 'POST',
    body: params,
  });
}
export async function addProgMatSns(params) {
  return request('/vehad/v1/addProgMatSns', {
    method: 'POST',
    body: params,
  });
}

export async function uploadWeather(params) {
  return request('/vehad/v1/weatherMat', {
    method: 'POST',
    body: params,
  });
}
export async function uploadTraffic(params) {
  return request('/vehad/v1/trafficInfoMat', {
    method: 'POST',
    body: params,
  });
}
export async function queryTask(params) {
  return request('/vehad/v1/pubProgTask', {
    method: 'GET',
    body: params,
  });
}
export async function setDevPower(params) {
  return request('/vehad/v1/setScrSwitch', {
    method: 'POST',
    body: params,
  });
}

export async function setDevReboot(params) {
  return request('/vehad/v1/devReboot', {
    method: 'POST',
    body: params,
  });
}
export async function setDevWIFI(params) {
  return request('/vehad/v1/switchDevWifiUsb', {
    method: 'POST',
    body: params,
  });
}
export async function setOtaFile(params) {
  return request('/vehad/v1/devUpdateOta', {
    method: 'POST',
    body: params,
  });
}
export async function setOtaUninstall(params) {
  return request('/vehad/v1/devSwUnload', {
    method: 'POST',
    body: params,
  });
}
export async function queryHwInfo(params) {
  return request('/vehad/v1/queryHwInfo', {
    method: 'POST',
    body: params,
  });
}

export async function fakeChartData() {
  return getFakeChartData;
}

export async function queryTags() {
  return request('/api/tags');
}

export async function queryBasicProfile() {
  return getProfileAdvancedData;
}

export async function queryAdvancedProfile() {
  return getProfileAdvancedData;
}

export async function updateAdvancedProfile(payload) {
  const { newrecord, index } = payload;
  const basic = getProfileAdvancedData;
  basic.advancedOperation1[index] = newrecord;
  return basic;
}

export async function queryFakeList(params) {
  // const reallist = await request('http://47.106.151.60:10000/vehad/v1/admats');
  const reallist = {
    fileList: ['a.txt', 'b.txt', 'c.txt', 'd.txt'],
  };
  // //console.log('realist', reallist);
  const fakelist = getFakeList(reallist.fileList.length);
  if (reallist) {
    fakelist.map((item, index) => (item.subDescription = reallist.fileList[index]));
  }
  return fakelist;
}

export async function fakeAccountLogin(params) {
  return request(
    '/vehUser/v1/login',
    {
      method: 'POST',
      body: params,
    },
    'vehUser'
  );
  // return {
  //   msgId: 1,
  //   status: 200,
  //   result: {
  //     msg: 'success',
  //     data: {
  //       token: 'b3ce86b7da96d4b5dabdf9d84beabf4',
  //     },
  //     code: 1000,
  //   },
  // };
}

export async function fakeRegister(params) {
  return request('/api/register', {
    method: 'POST',
    body: params,
  });
}
export async function queryMatDetail(params) {
  return request(`/vehad/v1/adMatDet`, {
    method: 'GET',
    body: params,
  });
}

export async function setDevBright(params) {
  return request('/vehad/v1/setBrightness', {
    method: 'POST',
    body: params,
  });
}
export async function setTimingSetBrightness(params) {
  return request('/vehad/v1/timingSetBrightness', {
    method: 'POST',
    body: params,
  });
}
export async function deviceTest(params) {
  return request('/vehad/v1/deviceTest', {
    method: 'POST',
    body: params,
  });
}

export async function queryAlarm(params) {
  return request('/vehad/v1/queryAlarmMsg', {
    method: 'POST',
    body: params,
  });
}

export async function setAlarm(params) {
  return request('/vehad/v1/removeDevAlarm', {
    method: 'POST',
    body: params,
  });
}
export async function setIpAddress(params) {
  return request('/vehad/v1/setServerAddr', {
    method: 'POST',
    body: params,
  });
}

export async function queryNotices() {
  return request('/api/notices');
}

export async function getDevInfo(params) {
  return request(`/vehad/v1/devInfos`, {
    method: 'GET',
    body: params,
  });
}
export async function expDevInfos(params) {
  return request(`/vehad/v1/expDevInfos`, {
    method: 'GET',
    body: params,
  });
}

export async function getProgInfo(params) {
  return request(`/vehad/v1/progNameCodes`, {
    method: 'GET',
    body: params,
  });
}

export async function addDevice(params) {
  return request('/vehad/v1/addDev', {
    method: 'POST',
    body: params,
  });
}

export async function editDevice(params) {
  return request('/vehad/v1/modifyDevBi', {
    method: 'POST',
    body: params,
  });
}

export async function removeDevice(params) {
  return request('/vehad/v1/delDevBi', {
    method: 'POST',
    body: params,
  });
}

export async function getDevDetail(params) {
  return request(`/vehad/v1/devInfoDet`, {
    method: 'GET',
    body: params,
  });
}

export async function getCityList(params) {
  return request(`/vehad/v1/cityCodes`, {
    method: 'GET',
    body: params,
  });
}

export async function getDevBasicInfo(params) {
  return request(`/vehad/v1/devBasicInfo`, {
    method: 'GET',
    body: params,
  });
}

export async function queryLog() {
  //console.log('querylog');
  return [
    {
      key: '1',
      time: '2018-05-19 21:11:00',
      level: '信息',
      code: '404',
      message: '设备上报基本信息',
    },
    {
      key: '2',
      time: '2018-05-19 21:11:00',
      level: '调试',
      code: '404',
      message: '设备磁盘空间报警',
    },
    {
      key: '3',
      time: '2018-05-19 21:11:00',
      level: '信息',
      code: '404',
      message: '设备上报基本信息',
    },
    { key: '4', time: '2018-05-19 21:11:00', level: '警告', code: '404', message: '网络故障' },
    {
      key: '5',
      time: '2018-05-19 21:11:00',
      level: '错误',
      code: '404',
      message: '设备上报基本信息',
    },
  ];
}

export async function getDevList() {
  // return request('/terminal');
  return [
    { key: '1', id: 'D61700031', name: 'D1', group: '大众汽车' },
    { key: '2', id: 'D61700032', name: 'D2', group: '大众汽车' },
    { key: '3', id: 'D61700033', name: 'D3', group: '东风汽车' },
    { key: '4', id: 'D61700035', name: 'D4', group: '东风汽车' },
    { key: '5', id: 'D61700036', name: 'D6', group: '东风汽车' },
    { key: '6', id: 'D61700037', name: 'D7', group: '东风汽车' },
    { key: '7', id: 'D61700038', name: 'D8', group: '东风汽车' },
  ];
}

// 写入-Gps信息间隔参数
export async function setGpsIntvTime(params) {
  return request('/vehad/v1/setParamInfo', {
    method: 'POST',
    body: params,
  });
}

// 读取-Gps信息事件间隔参数
export async function getGpsIntvTime(params) {
  return request('/vehad/v1/getParamInfo', {
    method: 'get',
    body: params,
  });
}

// 获取-指定设备历史运行轨迹
export async function getHistoryPath(params) {
  return request('/vehad/v1/devGpsTrack', {
    method: 'get',
    body: params,
  });
}

// export async function getSimcardList({
//   page,
//   pageSize,
//   iccid,
//   devId,
//   startTime,
//   endTime,
//   online,
//   status,
// }) {
//   let url = `${SIMAPI_HOST}/devsim/v1/simUsage/list?page=${page}&pageSize=${pageSize}&iccid=${iccid}&devId=${devId}&startDate=${encodeURIComponent(
//     startTime
//   )}&endDate=${encodeURIComponent(endTime)}`;
//   if (online !== undefined) url += `&online=${online}`;
//   if (status !== undefined) url += `&status=${status}`;
//   return fetch(url, {
//     method: 'get',
//   }).then(result => result.json());
// }
export async function getSimcardList(params) {
  return request(
    '/devsim/v1/simUsage/list',
    {
      method: 'get',
      body: params,
    },
    'sim'
  );
}
export async function getVehInfo(params) {
  return request(
    '/vehad/v1/vehPeriodOpts',
    {
      method: 'get',
      body: params,
    },
    'veh'
  );
}

// export async function getSimcardDetail({ iccid }) {
//   return fetch(`${SIMAPI_HOST}/devsim/v1/simUsageTrend?iccid=${iccid}`, {
//     method: 'get',
//   }).then(result => result.json());
// }
export async function getSimcardDetail(params) {
  return request(
    '/devsim/v1/simUsageTrend',
    {
      method: 'get',
      body: params,
    },
    'sim'
  );
}
// export function getSimExportUrl({ iccid, devId, startTime, endTime, online, status }) {
//   let url = `${SIMAPI_HOST}/devsim/v1/simCardUsage/export?iccid=${iccid}&devId=${devId}&startDate=${encodeURIComponent(
//     startTime
//   )}&endDate=${encodeURIComponent(endTime)}`;
//   if (online !== undefined) url += `&online=${online}`;
//   if (status !== undefined) url += `&status=${status}`;
//   return url;
// }
export function getSimExportUrl(params) {
  let sourceurl = `${SIMAPI_HOST}/devsim/v1/simCardUsage/export`;
  const token = getToken();
  params = { ...params, token };
  let formBody = [];
  for (const property in params) {
    if ({}.hasOwnProperty.call(params, property)) {
      // const encodedKey = encodeURIComponent(property);
      // const encodedValue = encodeURIComponent(params[property]);
      const encodedKey = property;
      const encodedValue = params[property];
      formBody.push(`${encodedKey}=${encodedValue}`);
    }
  }
  formBody = formBody.join('&');
  sourceurl = `${sourceurl}?${formBody} `;
  //console.log('sourceurl', sourceurl);
  return sourceurl;
}
export function getVehExportUrl(params) {
  return request(
    '/vehad/v1/expVehPeriodOpts',
    {
      method: 'get',
      body: params,
    },
    'veh'
  );
}
